package cn.veliger.springai.advisor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClientRequest;
import org.springframework.ai.chat.client.ChatClientResponse;
import org.springframework.ai.chat.client.advisor.api.CallAdvisor;
import org.springframework.ai.chat.client.advisor.api.CallAdvisorChain;

/**
 * 自定义CallAroundAdvisor
 *
 * @author veliger
 * create on 2025-06-28
 **/
@Slf4j
public class CusCallAroundAdvisor implements CallAdvisor {

    @Override
    public ChatClientResponse adviseCall(ChatClientRequest chatClientRequest, CallAdvisorChain callAdvisorChain) {
        long l = System.currentTimeMillis();
        //log.info("BEFORE: {}", chatClientRequest);
        ChatClientResponse advisedResponse = callAdvisorChain.nextCall(chatClientRequest);
        //log.info("AFTER: {}", advisedResponse);
        log.info("耗时：{}ms", System.currentTimeMillis() - l);
        return advisedResponse;

    }

    @Override
    public String getName() {
        return this.getClass().getSimpleName();
    }

    /**
     * 数字越小，越先执行，升序排序
     *
     * @return
     */
    @Override
    public int getOrder() {
        return 99;
    }
}
